package com.sbw.application.scaffold.remote;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

/**
 * @author sangbowei
 * @date 2018年8月25日
 *  redis模板类,项目启动后直接autowired使用,无需new该对象
 * 
 */
public class RedisClient {
	
	@Autowired
	private ValueOperations<String, Object> valueOperations;
	
	@Autowired
	private RedisTemplate<String, Object> redisTemplate;
	
	//获取数据
	public Object getValue(String key) {
		
		Object value = valueOperations.get(key);
		return value;
	}

	//保存数据
	public void setValue(String key, Object value) {
		
		valueOperations.set(key, value);
	}

	//保存数据并设置超时时间
	public void setValue(String key, Object value, Long expiredTime) {

		valueOperations.set(key, value, expiredTime, TimeUnit.SECONDS);
	}

	//删除数据
	public void removeKey(String key) {
		
		redisTemplate.delete(key);
	}

}
